<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib prefix="s" uri="/struts-tags"%>


<script type="text/javascript" src="js/jquery.itextclear.js"></script>
<script type="text/javascript" src="${ctx}/js/cookie.js"></script>
<script type="text/javascript">
	$(document)
			.ready(
					function() {
						$(
								'input[type=text], input[type=password], input[type=url], input[type=email], input[type=number], textarea',
								'.form').iTextClear();
					});
</script>
<!-- jQplot CSS -->

<link rel="stylesheet" media="screen" href="${ctx}/css/Tree.css" />
<!-- jQplot CSS END -->

<!-- DATATABLES CSS -->
<link rel="stylesheet" media="screen" href="lib/datatables/css/vpad.css" />
<script type="text/javascript"
	src="lib/datatables/js/jquery.dataTables.js"></script>
<!-- DATATABLES CSS END -->

<h1 class="page-title">${listTitle}</h1>

<div class="container_12 clearfix leading">

	<%@ include file="/WEB-INF/pages/common/common_tree.jsp"%>

	<div class="tabs side grid_8 leading">
		<p>
			职务名称： <select id="duty_select" onchange="dutyChangeCallback(this.value)">
			</select>
		</p>
	</div>
	<section id="list_content" class="clearfix"></section>
</div>

<div class="clear"></div>
<div class="container_12 clearfix leading">
	<section class="portlet grid_12 leading">
		<header>
			<h2>已选择</h2>
		</header>
		<section id="employee_has_sel_section">
			<%-- <a class="button" href="javascript:void(0)"><span
							style="background: url(images/img/add.png)" class="icon">&nbsp;</span>高级主管：5分</a>
						 --%>
		</section>

	</section>
</div>
<div class="container_12 clearfix leading" style="padding-left: 20px">
	<div class="form-action clearfix">
		<p>
			<a class="button" href="javascript:void(0)"
				onclick="dispatchCookies()"><span
				style="background: url(${ctx}/images/img/page_edit.png)"
				class="icon">&nbsp;</span>全部提交</a> <a class="button"
				href="javascript:void(0)" onclick="javascript:history.back()"><span
				style="background: url(${ctx}/images/img/arrow_undo.png)"
				class="icon">&nbsp;</span>返回</a>
		</p>
	</div>

</div>
<script type="text/javascript" src="${ctx}/js/Tree.js"></script>

<script type="text/javascript">
	var treeSelOrgId = ${organizationId};
	$(document).ready(function() {
		asyncUpdateSelectBody();
		findDuty(${organizationId});
	});

	function findDuty(organizationId) {
		treeSelOrgId = organizationId;
		$("#uniform-duty_select span:first").html("");//清除职务 
        $.getJSON("${ctx}/ajax/duty-list.xhtml?organizationId=" + organizationId, function(duties) {
            var selObj = $("#duty_select");
            selObj.html("");
            if (duties != null && duties.length != 0) {
                $.each(duties, function(i, duty) {
                    if(i == 0){
                        $("#uniform-duty_select span:first").html(duty.dutyName);//设置本次选择的职务
                    }
                    selObj.append("<option value='" + duty.id + "'>" + duty.dutyName + "</option>")
                });
                //selObj.get(0).selectedIndex = 1;
            }
        });
    }
	
	function dutyChangeCallback(dutyId){
		var url = "${ctx}${listAction}";
        var data = {"organizationId":treeSelOrgId,"dutyId":dutyId};
        //refreshListContent(url, data);
        $.ajax(url, {
            type: "POST",
            //data:{"organizationId":organizationId},
            data:data,
            dataType:"html",
            cache:false,
            success:function(a) {
                var obj = $("#list_content");
                obj.html("");
                obj.append(a);
            },
            complete:function() {
            }
        });
	}
	
	function asyncUpdateSelectBody() {
		$("#employee_has_sel_section").html("");
		var url = "${ctx}/ajax/train_employeetargets.xhtml";
        $.getJSON(url,function (employeePojos) {
            	if(employeePojos != null && employeePojos.length > 0){
            		var strHTML = "";
            		 $.each(employeePojos, function(i, target) {
            			 strHTML += "<a class=\"button\" href=\"javascript:void(0)\"><span style=\"background: url(images/img/add.png)\" class=\"icon\">&nbsp;</span>" + target.workName + "</a>";
                     });
            		$("#employee_has_sel_section").html(strHTML);
            	}else{
            		$("#employee_has_sel_section").html("暂无选择任何对象");
            	}
        });
	}
	// 提交计划目标选择 
	function dispatchCookies() {
		/* if(getCookie("duty_outing_target") != null){
            var url = "${ctx}/ajax/train-plan-employeetarget-save.xhtml";
            $.ajax(url, {
                type:"POST",
                data:{"duty_outing_target":getCookie("duty_outing_target")},
                dataType:"html",
                cache:false,
                success:function (a) {
                	window.location.href = "${ctx}/index.xhtml#train/outing_train_manage.xhtml?organizationId=${organizationId}&planId=${planId}";
                },
                complete:function () {
                	window.location.href = "${ctx}/index.xhtml#train/outing_train_manage.xhtml?organizationId=${organizationId}&planId=${planId}";
                }
            });
        }else{ */
			window.location.href = "${ctx}/index.xhtml#train/outing_train_manage.xhtml?organizationId=${organizationId}&planId=${planId}";
        //} 
	}

	
</script>